package wxpay

import (
	"github.com/astaxie/beego"
	"github.com/objcoding/wxpay"
)

var client *wxpay.Client
var appId string
var mchId string
var mchKey string
var notifyUrl string
var mchCertPath string

func init() {
	appId = beego.AppConfig.String("appId")
	mchId = beego.AppConfig.String("mchId")
	mchKey = beego.AppConfig.String("mchKey")
	notifyUrl = beego.AppConfig.String("notifyUrl")
	mchCertPath = beego.AppConfig.String("mchCertPath")
	if appId == "" {
		panic("appId can not be empty!")
	}
	if mchId == "" {
		panic("mchid can not be empty!")
	}
	if mchKey == "" {
		panic("mchKey can not be empty!")
	}
	if notifyUrl == "" {
		panic("notifyUrl can not be empty!")
	}
	account := wxpay.NewAccount(appId, mchId, mchKey, false)
	if mchCertPath != "" {
		account.SetCertData(mchCertPath)
	}
	client = wxpay.NewClient(account)
	client.SetSignType("MD5")
	// 设置http请求超时时间
	client.SetHttpConnectTimeoutMs(3000)
	// 设置http读取信息流超时时间
	client.SetHttpReadTimeoutMs(2000)
}
func GetWxPayClient() *wxpay.Client {
	return client
}

func GetAppId() string {
	return appId
}

func GetMchId() string {
	return mchId
}

func GetMchKey() string {
	return mchKey
}

func GetNotifyUrl() string {
	return notifyUrl
}

func GetMchCertPath() string {
	return mchCertPath
}
